package com.crm.common;

public abstract class CallBack {
    public Response execute() {
        String message = "成功";
        int code = 200;
        long a = System.currentTimeMillis();
        Object infoList = null;
        Object data = null;
        try {
            infoList = run();
        } catch (BusinessException e) {
            code = e.getCode();
            message = e.getMessage();
        } catch (Exception e) {
            e.printStackTrace();
            code = 500;
            message = "服务器内部异常，" + e.getMessage();
        }
        System.out.println("执行时间：" + (System.currentTimeMillis() - a) + "ms");
        if (infoList instanceof PageInfo pageInfo) {
            data = pageInfo.getData();
        }else{
            data = infoList;
        }
        return new Response(code, message, data);
    }

    protected abstract Object run();
}
